package bank.model.vo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Client extends Person{
	private int id;
	private static int nextId = 1;
	private int budget;
	public List accounts;
	
	
	
	public Client(String firstName, String lastName, String subName, int budget) {
		super(firstName, lastName, subName);
		this.setId(getNextId());		
		this.setBudget(budget);
		accounts=new ArrayList();//This list will contain all accounts of this client 
	}
	
	public Client(String firstName, String lastName,int budget) {
		super(firstName, lastName);
		this.setId(getNextId());		
		this.setBudget(budget);
		accounts=new ArrayList();//This list will contain all accounts of this client 
	}
	
	public Client(String firstName, String lastName, String subName) {
		super(firstName, lastName, subName);
		this.setId(getNextId());		
		accounts=new ArrayList();//This list will contain all accounts of this client 
	}

	

	private void setId(int id) {
		this.id = id;
		if (id >= nextId) 
			nextId = id+1;		
	}
	
	public int getId(){
		return id;
	}
	
	private static int getNextId() {		
		return nextId;
	}
	
	public static void setNextId(int id){
		if (id >= nextId)
		nextId = id;		
	}
	
	private void setBudget(int budget) {
		this.budget=budget;		
	}
	
	public int getBudget(){
		return budget;		
	}
	
	public void addAccount(Account account)	{
		accounts.add(account);
	}
	/**
	 * method applies find some account	  
	 * @return account
	 */	
	public Account getAccount(int id){
		int num;
		Account account=null;
		Iterator i=accounts.iterator();
		
		while(i.hasNext()){
			account=(Account)i.next();
			num=account.getId();
			if ( num==id)
			    break;			
		}
		return account;	
	}	
}